//
//  DrawView.m
//  08-绘制文字和图片
//
//  Created by J on 16/2/23.
//  Copyright © 2016年 J. All rights reserved.
//

#import "DrawView.h"

@implementation DrawView


- (void)drawRect:(CGRect)rect {
    
        NSString* str = @"绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字";
//    [str drawAtPoint:CGPointZero withAttributes:nil];
    
    
    NSMutableDictionary* textAtr = [NSMutableDictionary dictionary];
    //    设置文字颜色
    textAtr[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    textAtr[NSForegroundColorAttributeName] = [UIColor orangeColor];
    //空心文字
    textAtr[NSStrokeWidthAttributeName] = @5 ;
    textAtr[NSStrokeColorAttributeName] = [UIColor blackColor] ;//same as foreground color覆盖了字体颜色
    NSShadow* shadow = [NSShadow new];
    shadow.shadowBlurRadius = 10.0;
    shadow.shadowOffset = CGSizeMake(5, 5);
    shadow.shadowColor = [UIColor purpleColor];
    textAtr[NSShadowAttributeName] = shadow;

    [str drawInRect:rect withAttributes:textAtr];
    
    
    
}

//绘制图片
- (void)drawPic:(CGRect)rect{
        UIRectClip(CGRectMake(0, 0, 50, 50));//裁剪 设置裁剪区域把超出部分全部裁剪掉
        UIImage* imageName = [UIImage imageNamed:@"001"];
        [imageName drawAtPoint:CGPointZero];//默认绘制的内容跟图片尺寸一样大 如果图片大于当前view 能显示多少显示多少
        [imageName drawInRect:rect];//整个view内现实图片 如果图片没有当前rect大拉伸
         [imageName drawAsPatternInRect:rect];//平铺
        UIRectClip(CGRectMake(0, 0, 50, 50));//裁剪 放在绘图之后无效
    
    
}


// 绘制文字换行与不换行
- (void)drawInRect{
    
//    NSString* str = @"绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字绘制文字";
    
    //    [str drawAtPoint:CGPointZero withAttributes:nil];//不会自动换行
    //    [str drawInRect:rect withAttributes:nil];//会自动换行

}
//绘制文字

- (void)attrText{
    
    NSString* str = @"绘制文字";
    
    ///  @param CGPoint   起点
    ///  @Attributes  文字属性 :颜色字体大小 nil就为默认的黑色
    NSMutableDictionary* textAtr = [NSMutableDictionary dictionary];
    //    设置文字颜色
    textAtr[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    textAtr[NSForegroundColorAttributeName] = [UIColor orangeColor];
    //空心文字
    textAtr[NSStrokeWidthAttributeName] = @5 ;
    textAtr[NSStrokeColorAttributeName] = [UIColor blackColor] ;//same as foreground color覆盖了字体颜色
    NSShadow* shadow = [NSShadow new];
    shadow.shadowBlurRadius = 10.0;
    shadow.shadowOffset = CGSizeMake(5, 5);
    shadow.shadowColor = [UIColor purpleColor];
    textAtr[NSShadowAttributeName] = shadow;
    [str drawAtPoint:CGPointZero withAttributes:textAtr];
    
    
    
    
}


@end
